<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
		xmlns:ui="http://java.sun.com/jsf/facelets"
		xmlns:f="http://java.sun.com/jsf/core" 
		xmlns:c="http://java.sun.com/jstl/core" 
		xmlns:h="http://java.sun.com/jsf/html"
		xmlns:a4j="http://richfaces.org/a4j"
		xmlns:rich="http://richfaces.org/rich">
		
	<ui:composition>
	
		<h:form>
		
					<h:panelGrid columns="2">			
							<h:panelGroup>				
								<h:outputLabel value="Rooms: "/><a href="#" onclick="Richfaces.showModalPanel('roomSelectionWindow');">Select Rooms</a>
								<h:panelGroup id="selectedRooms">			
									<c:set var="found" value="0"/>
									<ul>				
										<c:forEach items="#{buildings}" var="building">
											<c:forEach items="#{building.rooms}" var="room">
												<c:if test="#{ not room.dormitory and room.selected}">					
													<li>#{room.roomNumber} ( #{building.name} )</li>
													<c:set var="found" value="1"/>
												</c:if> 	
											</c:forEach>
										</c:forEach>
										<c:if test="#{found eq 0}" >	
											<li>No Rooms Selected</li>
										</c:if>		
									</ul>
								</h:panelGroup>
							</h:panelGroup>
							<h:panelGroup>
								<h:outputLabel value="Dormitory Beds: "/> <a href="#" onclick="Richfaces.showModalPanel('dormitorySelectionWindow');">Select Beds</a>
								<h:panelGroup id="selectedDormitories">			
									<c:set var="found" value="0"/>
									<ul>
										<c:forEach items="#{buildings}" var="building">
											<c:forEach items="#{building.rooms}" var="room">
												<c:if test="#{room.dormitory}" >
													<c:forEach items="#{room.beds}" var="bed">
														<c:if test="#{ bed.selected}" >	
															<li>#{bed.bedNumber} ( #{building.name} - #{room.roomNumber} )</li>
															<c:set var="found" value="1"/>
														</c:if>
													</c:forEach>
												</c:if> 	
											</c:forEach>
										</c:forEach>
										<c:if test="#{found eq 0}" >	
											<li>No Beds Selected</li>
										</c:if>		
									</ul>
								</h:panelGroup>
							</h:panelGroup>
						</h:panelGrid>
	</h:form>	
						
	<rich:modalPanel id="roomSelectionWindow" minHeight="300" minWidth="600" autosized="true"
			zindex="2000" height="300"  >
			<f:facet name="header">
				<h:outputText value="Rooms"/>
			</f:facet>
			<f:facet name="controls">
            	<h:graphicImage value="/images/close.gif" 
            					style="cursor:pointer" 
            					onclick="Richfaces.hideModalPanel('roomSelectionWindow')" />
      		</f:facet>
		<div class="modalPanelInternal">		
			<h:form>
				<c:forEach items="#{buildings}" var="building">
					<h4 style="text-decoration: underline;">#{building.name}</h4>
					<c:forEach begin="1" end="#{building.floors}" var="floor">
						<h5>Floor #{floor}</h5>		
							<h:panelGroup>															
									<h:panelGrid columns="3">
										<c:set var="found" value="0"/>
										<c:forEach items="#{building.rooms}" var="room">
											<c:if test="#{not room.dormitory and room.floor eq floor}">
												<h:panelGroup>
													<div style="height:75px; text-align: left; padding:5px; margin: 5px; border: thin solid grey; #{room.occupied ? 'background-color: gray;':''}">																
														<div><h:selectBooleanCheckbox value="#{room.selected}" disabled="#{room.occupied}" />  #{room.roomNumber}</div>
														<h:panelGroup layout="block">															
															<div>Rate(A): #{room.rate}</div>
														</h:panelGroup>
														<h:panelGroup rendered="#{not room.occupied}" layout="block">															
															<div>Rate(P):<h:inputText value="#{room.proposedRate}" style="font-size:8pt;width: 23px;"/></div>
														</h:panelGroup>														
													</div>													
												</h:panelGroup>
												<c:set var="found" value="1"/>
											</c:if>															
										</c:forEach>
									</h:panelGrid>
									<c:if test="#{found eq 0}" >
										No Rooms found
									</c:if>
							</h:panelGroup>
							<hr/>
						</c:forEach>			
					</c:forEach>		
				<br/>		
				<a4j:commandButton value="Done" reRender="selectedRooms" oncomplete="Richfaces.hideModalPanel('roomSelectionWindow');"/>			
			</h:form>
		</div>
	</rich:modalPanel>
	
	<rich:modalPanel id="dormitorySelectionWindow" minHeight="300" minWidth="600" autosized="true" zindex="2000"  >
		<f:facet name="header">
			<h:outputText value="Dormitories"></h:outputText>
		</f:facet>
		<f:facet name="controls">
          		<h:graphicImage value="/images/close.gif" 
          					style="cursor:pointer" 
          					onclick="Richfaces.hideModalPanel('dormitorySelectionWindow')" />
    			</f:facet>				
		<div class="modalPanelInternal">
			<h:form>			
			<c:forEach items="#{buildings}" var="building">
				<h:panelGroup>											
					<c:forEach items="#{building.rooms}" var="room">
						<c:if test="#{room.dormitory}">
							<h:panelGroup>
								<h5 style="text-decoration: underline;">#{building.name} - Dormitory #{room.roomNumber}</h5>
								<h:panelGrid columns="3" >
									<c:forEach items="#{room.beds}" var="bed">
										<h:panelGroup >
											<div style="height:75px; text-align: left; padding:5px; margin: 5px; border: thin solid grey; #{bed.occupied ? 'background-color: gray;':''}">
												<div><h:selectBooleanCheckbox value="#{bed.selected}" disabled="#{bed.occupied}" />  #{bed.bedNumber}</div>
												<h:panelGroup layout="block">															
													<div>Rate(A): #{room.rate}</div> 													
												</h:panelGroup>
												<h:panelGroup rendered="#{not bed.occupied}" layout="block">															
													<div>Rate(P):<h:inputText size="4" value="#{bed.proposedRate}" style="font-size:8pt; width: 23px;"/></div> 													
												</h:panelGroup>											
											</div>
										</h:panelGroup>
										<c:set var="found" value="1"/>
									</c:forEach>
								</h:panelGrid>
								<c:if test="#{empty room.beds}" >
									No Beds found
								</c:if>								
							</h:panelGroup>							
						</c:if>															
					</c:forEach>										
				</h:panelGroup>
				<hr/>
			</c:forEach>		
			<br/>		
			<a4j:commandButton value="Done" action="#{admissionController.action}" reRender="selectedDormitories" oncomplete="Richfaces.hideModalPanel('dormitorySelectionWindow');"/>
			</h:form>
			</div>
		</rich:modalPanel>	
						
	</ui:composition>	
</html>
